package project;

public class Experiment {

	static String str = "soybean1987.txt"; // (47x35)
	static int instances = 47;
	static int attributes = 35;
	static int k = 4;
	static int initialmethod = 1;
	static int times = 100;

	public static void main(String[] args) {

		// Setup data
		String[][] data = DataManipulation
				.txt2array(str, instances, attributes);
		System.out
				.println("----------------------------------------------------------- Initial Data: ----------------------------------------------------------------------");
		DataManipulation.printStringArray2d(data);
		int experiment[][] = new int[times][k];
		for (int i = 0; i < times; i++) {
			// K-modes Algorithm
			KmodesAlgorithm kma = new KmodesAlgorithm(data, k, initialmethod);
			// Step 1:
			System.out.println("\nInitial mode:");
			DataManipulation.printMode(kma.getModes());
			// Step 2&3&4
			kma.checkAndUpdate();
			// --- result after clustering-----
			System.out
					.println("\n\n------------------------------------------------------------- Result -------------------------------------------------------------------------------------");
			DataManipulation.printIntArray(kma.getResultTbl());
			System.out
					.println("\n--------------------------------------------------------------------------------------------------------------------------------------------------------");
			System.out
					.println("\n--------------------------------------------------------------- K-modes! ------------------------------------------------------------------------------------");
			DataManipulation.printMode(kma.getModes());
			System.out
					.println("\n--------------------------------------------------------------- statistic ------------------------------------------------------------------------------------");
			experiment[i] = kma.statistic();
		}
		System.out.println("\nstarting experiment!!!!\n");
		DataManipulation.printIntArray2d(experiment);

		Integer[][] experimentInteger = new Integer[experiment.length][experiment[0].length];

		for (int i = 0; i < experiment.length; i++) {
			for (int j = 0; j < experiment[0].length; j++) {
				experimentInteger[i][j] = experiment[i][j];
			}
		}
		System.out.println("\nstarting statistic!!!!\n");
		experimentInteger = DataManipulation.removeDuplicate(experimentInteger);
		int[] temp = new int[k];
		for (Integer[] exp : experimentInteger) {
			for (int j = 0; j < exp.length; j++) {
				System.out.print("" + exp[j] + " ");
			}
			temp = DataManipulation.toPrimitive(exp);
			System.out.println("is observered with "
					+ DataManipulation.count(temp, experiment) + " cases");
		}
	}
}
